package com.gitee.wsl.time.chinese

import kotlin.test.Test
import kotlin.test.assertEquals


/**
 * 八字测试
 *
 * @author 6tail
 */
class BaZiTestNew {
    @Test
    fun test1() {
        val solar = Solar(2020, 1, 1, 22, 35, 0)
        val lunar = solar.lunar
        //己亥 丙子 癸卯 癸亥
        println(lunar.eightChar)
    }

    @Test
    fun test2() {
        val solar = Solar(2020, 1, 6, 14, 35, 0)
        val lunar = solar.lunar
        //己亥, 丁丑, 戊申, 己未]
        println(lunar.eightChar)
    }

    @Test
    fun test3() {
        val solar = Solar(2020, 1, 6, 3, 35, 0)
        val lunar = solar.lunar
        //己亥, 丁丑, 戊辰, 癸亥]
        println(lunar.eightChar)
    }

    @Test
    fun test4() {
        val solar = Solar(2020, 1, 26, 21, 41, 0)
        val lunar = solar.lunar
        //己亥, 丙子, 戊申, 甲寅]
        println(lunar.eightChar)
    }

    @Test
    fun test5() {
        val solar = Solar(2020, 2, 4, 1, 42, 0)
        val lunar = solar.lunar
        //己亥, 丁丑, 丁丑, 辛丑]
        println(lunar.eightChar)
    }

    @Test
    fun test6() {
        val solar = Solar(2020, 2, 5, 21, 43, 0)
        val lunar = solar.lunar
        //庚子, 戊寅, 戊寅, 癸亥]
        println(lunar.eightChar)
    }

    @Test
    fun testBazi2Solar6() {
        val l = Solar.fromBaZi("庚子", "戊寅", "戊寅", "癸亥")
        // [2020-02-05 22:00:00, 1960-02-20 22:00:00]
        for (solar in l) {
            println(solar!!.toFullString())
        }
    }

    @Test
    fun test7() {
        val solar = Solar(2020, 5, 26, 23, 43, 0)
        val lunar = solar.lunar
        // [庚子, 辛巳, 庚午, 丙子]
        println(lunar.eightChar)
    }

    @Test
    fun testBazi2Solar7() {
        val l = Solar.fromBaZi("庚子", "辛巳", "庚午", "丙子")
        // [2020-05-26 23:00:00, 2020-05-27 00:00:00]
        for (solar in l) {
            println(solar!!.toFullString())
        }
    }

    @Test
    fun testBazi2Solar() {
        val l = Solar.fromBaZi("庚子", "癸未", "乙丑", "丁亥")
        // [2020-07-21 22:00:00, 1960-08-05 22:00:00]
        for (solar in l) {
            println(solar!!.toFullString())
        }
    }

    @Test
    fun testBazi2Solar2() {
        val l = Solar.fromBaZi("庚子", "戊子", "己卯", "庚午")
        // [1960-12-17 12:00:00, 1901-01-01 12:00:00]
        for (solar in l) {
            println(solar!!.toFullString())
        }
    }

    @Test
    fun testBazi2Solar3() {
        val l = Solar.fromBaZi("辛丑", "丁酉", "丙寅", "戊戌")
        // [2021-09-15 20:00:00 星期三 处女座, 1961-09-30 20:00:00 星期六 天秤座]
        for (solar in l) {
            println(solar!!.toFullString())
        }
    }

    @Test
    fun testBaziShiShenZhi() {
        val solar = Solar(2020, 1, 1, 22, 35, 0)
        val lunar = solar.lunar
        //己亥 丙子 癸卯 癸亥
        println(lunar.eightChar)
        //七杀
        println(lunar.eightChar!!.yearShiShenGan)
        //正财
        println(lunar.eightChar!!.monthShiShenGan)
        //日主
        println(lunar.eightChar!!.dayShiShenGan)
        //比肩
        println(lunar.eightChar!!.timeShiShenGan)

        //[劫财, 伤官]
        println(lunar.eightChar!!.yearShiShenZhi)
        //[比肩]
        println(lunar.eightChar!!.monthShiShenZhi)
        //[食神]
        println(lunar.eightChar!!.dayShiShenZhi)
        //[劫财, 伤官]
        println(lunar.eightChar!!.timeShiShenZhi)
    }

    /**
     * 起运
     */
    @Test
    fun testQiYun() {
        var solar = Solar(1983, 2, 15, 20, 0, 0)
        var lunar = solar.lunar
        var bazi = lunar.eightChar
        var yun = bazi!!.getYun(0)
        assertEquals(6, yun.startYear)
        assertEquals(2, yun.startMonth)
        assertEquals(20, yun.startDay)
        assertEquals("1989-05-05", yun.startSolar.toYmd())

        solar = Solar(2013, 7, 13, 16, 17, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(0)
        assertEquals(8, yun.startYear)
        assertEquals(4, yun.startMonth)
        assertEquals(0, yun.startDay)
        assertEquals("2021-11-13", yun.startSolar.toYmd())

        solar = Solar(2020, 8, 18, 10, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(0)
        assertEquals(3, yun.startYear)
        assertEquals(8, yun.startMonth)
        assertEquals(0, yun.startDay)
        assertEquals("2024-04-18", yun.startSolar.toYmd())

        solar = Solar(1972, 6, 15, 0, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        assertEquals(7, yun.startYear)
        assertEquals(5, yun.startMonth)
        assertEquals(10, yun.startDay)
        assertEquals("1979-11-25", yun.startSolar.toYmd())

        solar = Solar(1968, 11, 22, 0, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        assertEquals(5, yun.startYear)
        assertEquals(1, yun.startMonth)
        assertEquals(20, yun.startDay)
        assertEquals("1974-01-11", yun.startSolar.toYmd())

        solar = Solar(1968, 11, 23, 0, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        assertEquals(4, yun.startYear)
        assertEquals(9, yun.startMonth)
        assertEquals(20, yun.startDay)
        assertEquals("1973-09-12", yun.startSolar.toYmd())

        solar = Solar(1992, 2, 2, 12, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        assertEquals(9, yun.startYear)
        assertEquals(0, yun.startMonth)
        assertEquals(10, yun.startDay)
        assertEquals("2001-02-12", yun.startSolar.toYmd())
    }

    /**
     * 大运
     */
    @Test
    fun testDaYun() {
        var startYears = intArrayOf(1983, 1989, 1999, 2009, 2019, 2029, 2039, 2049, 2059, 2069)
        var endYears = intArrayOf(1988, 1998, 2008, 2018, 2028, 2038, 2048, 2058, 2068, 2078)
        var startAges = intArrayOf(1, 7, 17, 27, 37, 47, 57, 67, 77, 87)
        var endAges = intArrayOf(6, 16, 26, 36, 46, 56, 66, 76, 86, 96)
        var yearGanZhi = arrayOf<String>("", "乙卯", "丙辰", "丁巳", "戊午", "己未", "庚申", "辛酉", "壬戌", "癸亥")
        var solar = Solar(1983, 2, 15, 20, 0, 0)
        var lunar = solar.lunar
        var bazi = lunar.eightChar
        var yun = bazi!!.getYun(0)
        var l = yun.daYun
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val daYun = l[i]
                assertEquals(startYears[i], daYun.startYear)
                assertEquals(endYears[i], daYun.endYear)
                assertEquals(startAges[i], daYun.startAge)
                assertEquals(endAges[i], daYun.endAge)
                assertEquals(yearGanZhi[i], daYun.ganZhi)
                i++
            }
        }

        startYears = intArrayOf(1992, 2001, 2011, 2021, 2031, 2041, 2051, 2061, 2071, 2081)
        endYears = intArrayOf(2000, 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090)
        startAges = intArrayOf(1, 10, 20, 30, 40, 50, 60, 70, 80, 90)
        endAges = intArrayOf(9, 19, 29, 39, 49, 59, 69, 79, 89, 99)
        yearGanZhi = arrayOf<String>("", "庚子", "己亥", "戊戌", "丁酉", "丙申", "乙未", "甲午", "癸巳", "壬辰")
        solar = Solar(1992, 2, 2, 12, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        l = yun.daYun
        var i = 0
        val j = l.size
        while (i < j) {
            val daYun = l[i]
            assertEquals(startYears[i], daYun.startYear)
            assertEquals(endYears[i], daYun.endYear)
            assertEquals(startAges[i], daYun.startAge)
            assertEquals(endAges[i], daYun.endAge)
            assertEquals(yearGanZhi[i], daYun.ganZhi)
            i++
        }
    }

    /**
     * 流年
     */
    @Test
    fun testLiuNian() {
        var solar = Solar(1983, 2, 15, 20, 0, 0)
        var lunar = solar.lunar
        var bazi = lunar.eightChar
        var yun = bazi!!.getYun(0)
        var daYun = yun.daYun

        var years = intArrayOf(1983, 1984, 1985, 1986, 1987, 1988)
        var ages = intArrayOf(1, 2, 3, 4, 5, 6)
        var ganZhi = arrayOf<String>("癸亥", "甲子", "乙丑", "丙寅", "丁卯", "戊辰")
        var l = daYun[0].liuNian
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val liuNian = l[i]
                assertEquals(years[i], liuNian.year)
                assertEquals(ages[i], liuNian.age)
                assertEquals(ganZhi[i], liuNian.ganZhi)
                i++
            }
        }

        years = intArrayOf(2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038)
        ages = intArrayOf(47, 48, 49, 50, 51, 52, 53, 54, 55, 56)
        ganZhi = arrayOf<String>("己酉", "庚戌", "辛亥", "壬子", "癸丑", "甲寅", "乙卯", "丙辰", "丁巳", "戊午")
        l = daYun[5].liuNian
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val liuNian = l[i]
                assertEquals(years[i], liuNian.year)
                assertEquals(ages[i], liuNian.age)
                assertEquals(years[i].toString() + "年", ganZhi[i], liuNian.ganZhi)
                i++
            }
        }

        solar = Solar(1981, 8, 16, 9, 30, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        daYun = yun.daYun

        years = intArrayOf(1981, 1982, 1983)
        ages = intArrayOf(1, 2, 3)
        ganZhi = arrayOf<String>("辛酉", "壬戌", "癸亥")
        l = daYun[0].liuNian
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val liuNian = l[i]
                assertEquals(years[i], liuNian.year)
                assertEquals(ages[i], liuNian.age)
                assertEquals(ganZhi[i], liuNian.ganZhi)
                i++
            }
        }

        years = intArrayOf(1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993)
        ages = intArrayOf(4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
        ganZhi = arrayOf<String>("甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午", "辛未", "壬申", "癸酉")
        l = daYun[1].liuNian
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val liuNian = l[i]
                assertEquals(years[i], liuNian.year)
                assertEquals(ages[i], liuNian.age)
                assertEquals(ganZhi[i], liuNian.ganZhi)
                i++
            }
        }

        solar = Solar(1981, 8, 8, 1, 30, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        daYun = yun.daYun

        l = daYun[0].liuNian
        assertEquals(0, l.size)

        years = intArrayOf(1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990)
        ages = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
        ganZhi = arrayOf<String>("辛酉", "壬戌", "癸亥", "甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午")
        l = daYun[1].liuNian
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val liuNian = l[i]
                assertEquals(years[i], liuNian.year)
                assertEquals(ages[i], liuNian.age)
                assertEquals(ganZhi[i], liuNian.ganZhi)
                i++
            }
        }

        solar = Solar(1992, 2, 2, 12, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        daYun = yun.daYun

        years = intArrayOf(1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000)
        ages = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
        ganZhi = arrayOf<String>("壬申", "癸酉", "甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰")
        l = daYun[0].liuNian
        var i = 0
        val j = l.size
        while (i < j) {
            val liuNian = l[i]
            assertEquals(years[i], liuNian.year)
            assertEquals(ages[i], liuNian.age)
            assertEquals(ganZhi[i], liuNian.ganZhi)
            i++
        }
    }

    /**
     * 小运
     */
    @Test
    fun testXiaoYun() {
        var solar = Solar(1983, 2, 15, 20, 0, 0)
        var lunar = solar.lunar
        var bazi = lunar.eightChar
        var yun = bazi!!.getYun(0)
        var daYun = yun.daYun

        var years = intArrayOf(1983, 1984, 1985, 1986, 1987, 1988)
        var ages = intArrayOf(1, 2, 3, 4, 5, 6)
        var ganZhi = arrayOf<String>("乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰")
        var l = daYun[0].xiaoYun
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val xiaoYun = l[i]
                assertEquals(years[i], xiaoYun.year)
                assertEquals(ages[i], xiaoYun.age)
                assertEquals(ganZhi[i], xiaoYun.ganZhi)
                i++
            }
        }

        years = intArrayOf(2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038)
        ages = intArrayOf(47, 48, 49, 50, 51, 52, 53, 54, 55, 56)
        ganZhi = arrayOf<String>("辛酉", "壬戌", "癸亥", "甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午")
        l = daYun[5].xiaoYun
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val xiaoYun = l[i]
                assertEquals(years[i], xiaoYun.year)
                assertEquals(ages[i], xiaoYun.age)
                assertEquals(years[i].toString() + "年", ganZhi[i], xiaoYun.ganZhi)
                i++
            }
        }

        solar = Solar(1992, 2, 2, 12, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        daYun = yun.daYun

        ganZhi = arrayOf<String>("丁巳", "丙辰", "乙卯", "甲寅", "癸丑", "壬子", "辛亥", "庚戌", "己酉")
        l = daYun[0].xiaoYun
        var i = 0
        val j = l.size
        while (i < j) {
            val xiaoYun = l[i]
            assertEquals(ganZhi[i], xiaoYun.ganZhi)
            i++
        }
    }

    /**
     * 流月
     */
    @Test
    fun testLiuYue() {
        var solar = Solar(1983, 2, 15, 20, 0, 0)
        var lunar = solar.lunar
        var bazi = lunar.eightChar
        var yun = bazi!!.getYun(0)
        var daYun = yun.daYun

        var ganZhi = arrayOf<String>(
            "甲寅",
            "乙卯",
            "丙辰",
            "丁巳",
            "戊午",
            "己未",
            "庚申",
            "辛酉",
            "壬戌",
            "癸亥",
            "甲子",
            "乙丑"
        )
        var liuNian = daYun[0].liuNian
        var l = liuNian[0].liuYue
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val liuYue = l[i]
                assertEquals(ganZhi[i], liuYue.ganZhi)
                i++
            }
        }

        ganZhi = arrayOf<String>(
            "庚寅",
            "辛卯",
            "壬辰",
            "癸巳",
            "甲午",
            "乙未",
            "丙申",
            "丁酉",
            "戊戌",
            "己亥",
            "庚子",
            "辛丑"
        )
        liuNian = daYun[4].liuNian
        l = liuNian[2].liuYue
        run {
            var i = 0
            val j = l.size
            while (i < j) {
                val liuYue = l[i]
                assertEquals(ganZhi[i], liuYue.ganZhi)
                i++
            }
        }


        solar = Solar(1992, 2, 2, 12, 0, 0)
        lunar = solar.lunar
        bazi = lunar.eightChar
        yun = bazi!!.getYun(1)
        daYun = yun.daYun

        ganZhi = arrayOf<String>(
            "壬寅",
            "癸卯",
            "甲辰",
            "乙巳",
            "丙午",
            "丁未",
            "戊申",
            "己酉",
            "庚戌",
            "辛亥",
            "壬子",
            "癸丑"
        )
        liuNian = daYun[0].liuNian
        l = liuNian[0].liuYue
        var i = 0
        val j = l.size
        while (i < j) {
            val liuYue = l[i]
            assertEquals(ganZhi[i], liuYue.ganZhi)
            i++
        }
    }
}
